<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
$str="省份证530103188004160678";
$str1="省份证@530103188004160678";

//$res=  substr($str, 9, 18);//截取字符串

$res=  strstr($str1, "@");   //获取某个字符之后的
$res1=str_replace('@','',$res);

echo '截取前字符串:'.$str1."<br>";
//$res1=  strlen($str);//获得字符串长度
echo '截取后字符串:'.$res1;

//构造字符串
  $str123 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  echo "原字符串：".$str123."";
  //按各种方式进行截取
  $str1231 = substr($str123,5);
  echo "从第5个字符开始取至最后：".$str1231."";
  $str1232 = substr($str123,9,4);
  echo "从第9个字符开始取4个字符：".$str1232."";
  $str1233 = substr($str123,-5);
  echo "取倒数5个字符：".$str1233."";
  $str1234 = substr($str123,-8,4);
  echo "从倒数第8个字符开始向后取4个字符：".$str1234."";
  $str1235 = substr($str123,-8,-2);
  echo "从倒数第8个字符开始取到倒数第2个字符为止：".$str1235."";
  
  
  echo "中文截取";
  function GBsubstr($string, $start, $length) {
        if(strlen($string)>$length){
            $str=null;
            $len=$start+$length;
            for($i=$start;$i<$len;$i++){
                if(ord(substr($string,$i,1))>0xa0){
                    $str.=substr($string,$i,2);
                    $i++;
                }else{
                    $str.=substr($string,$i,1);
                }
            }
           return $str.'...';
        }else{
           return $string;
        }
    }